package main

import (
	"context"
	"fmt"
	"lwhnn/utils"
)

func main() {
	ctx, cancel := context.WithCancel(context.Background()) // 可以调用ctx通知机制告知协程退出
	go Run(ctx)
	utils.WaitTerm(cancel) // 防止程序退出
}

func Run(ctx context.Context) {
	// 查询数据
	rows, _ := utils.Db.Query("select VideId, VideName, CamIP from kd_vide_define_copy where VideId in(41, 42, 45, 46)")

	// 组装数据
	for rows.Next() {
		task := new(Task)
		rows.Scan(&task.VideId, &task.VideName, &task.CamIP)
		if task.VideId < 45 {
			continue
			//task.TypeId = int8(task.VideId - 40)
		} else {
			task.TypeId = int8(task.VideId - 42)
		}
		task.ReqUrl = fmt.Sprintf("%s%d", "http://58.48.78.146:3351/pic?vid=", task.VideId)
		task.TimeInterval = 10

		go task.Work()
	}

}
